package php.code.statements;

import php.code.Block;
import php.code.indentation.Indentable;
import php.code.instructions.Instruction;

/**
 * Created by nuno-rafael-figueiredo on 25-05-2014.
 */
public abstract class Statement extends Instruction {
    public final Block block = new Block(getIndentation()) {
        @Override
        protected String open() {
            return useBrackets() ? "{" : "";
        }

        @Override
        protected String close() {
            return useBrackets() ? "}" : "";
        }
    };

    {
        indentationProperty.addListener((observable, oldValue, newValue) -> block.setIndentation(getIndentation()));
    }

    public Statement(Indentable parent, boolean generatePhpDoc) {
        super(parent, generatePhpDoc);
    }

    public Statement(boolean generatePhpDoc) {
        super(generatePhpDoc);
    }

    protected Statement() {
        super(false);
    }

    protected abstract boolean useBrackets();

    @Override
    protected final String getCode() {
        return String.format(getIndentation() + getSignature() + block);
    }

    protected abstract String getSignature();
}
